package com.aires.testbeanfactorypostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @program: spring
 * @description: bean工厂的后置处理器(在bean的definition都加载到容器中去了之后但是还没有实例化bean的时候执行)
 * @author: fan zhengxiang
 * @create: 2020-11-02 20:49
 */
@Component
public class AiresBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("调用AiresBeanFactoryPostProcessor的postProcessBeanFactory方法");
		Arrays.stream(beanFactory.getBeanDefinitionNames()).forEach(e->{
			if ("airesLog".equals(e)){
				BeanDefinition beanDefinition = beanFactory.getBeanDefinition(e);
				System.out.println(beanDefinition.toString());
				beanDefinition.setLazyInit(true);
			}
		});
	}
}